let App = getApp();

Page({
  data: {
    // banner轮播组件属性
    indicatorDots: false, // 是否显示面板指示点	
    autoplay: true, // 是否自动切换
    interval: 3000, // 自动切换时间间隔
    duration: 800, // 滑动动画时长
    imgHeights: {}, // 图片的高度
    imgCurrent: {}, // 当前banne所在滑块指针

    // 页面元素
    lunboData: [{
      "imgurl": "http://img.wgmf.com/pro_1_091564053396222.jpg",
        "id": 1
      },
      {
        "imgurl": 'http://img.wgmf.com/pro_1_181564053396233.jpg',
        "id": 2
      },
      {
        "imgurl": "http://img.wgmf.com/pro_1_171564053396232.jpg",
        "id": 3
      },
      {
        "imgurl": "http://img.wgmf.com/pro_1_121564109761691.jpg",
        "id": 4
      }
    ],
    newest: [{
      "goods_name": "小米9",
      "spec": [{
        "goods_price": 2799.00
      }],
      "image": [{
        "file_path": "//i1.mifile.cn/a1/pms_1550642182.7527088!220x220.jpg"
      }]
    }, {
      "goods_name": "小米mix 3",
      "spec": [{
        "goods_price": 3299.00
      }],
      "image": [{
        "file_path": "//i1.mifile.cn/a1/pms_1540429613.4617799!220x220.jpg"
      }]
    }, {
      "goods_name": "redmiK20",
      "spec": [{
        "goods_price": 2099.00
      }],
      "image": [{
        "file_path": "//i1.mifile.cn/a1/pms_1558857780.47412427!220x220.jpg"
      }]
    }, {
      "goods_name": "remik20 Pro",
      "spec": [{
        "goods_price": 2699.00
      }],
      "image": [{
        "file_path": "//i1.mifile.cn/a1/pms_1550642182.7527088!220x220.jpg"
      }]
    }],
    customerbar: [{
      "name": "签到",
      "image":  "../../resources/images/indexBar/Sign.png"
    }, {
      "name": "会员",
        "image":  "../../resources/images/indexBar/Member.png"
    }, {
      "name": "折扣",
        "image": "../../resources/images/indexBar/ShoppingBags.png"
    }, {
      "name": "严选",
        "image":  "../../resources/images/indexBar/SpecialChoose.png"
    }, {
      "name": "积分",
        "image":"../../resources/images/indexBar/Integral.png"
    }],
    best: [{
      "goods_name": "芒果燕麦 280g",
      "spec": [{
        "goods_price": 29.0
      }],
      "image": [{
        "file_path": "http://img.wgmf.com/pro_1_541561631027154.jpg"
      }]
    }, {
        "goods_name": "黑芝麻糊 360g",
        "spec": [{
          "goods_price": 59.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_571561631027155.jpg"
        }]
      }, {
        "goods_name": "能力肌肉粉 100ml",
        "spec": [{
          "goods_price": 99.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_401561631027134.jpg"
        }]
      }, {
        "goods_name": "无糖燕麦片 500g",
        "spec": [{
          "goods_price": 99.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_381561631027132.jpg"
        }]
      }, {
        "goods_name": "APPLE IPHONE X(A1903) 64G 深空灰色 联通移动4...",
        "spec": [{
          "goods_price": 2799.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_421561631027140.jpg"
        }]
      }, {
        "goods_name": "APPLE IPHONE X(A1903) 64G 深空灰色 联通移动4...",
        "spec": [{
          "goods_price": 2799.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_571561631027155.jpg"
        }]
      }, {
        "goods_name": "APPLE IPHONE X(A1903) 64G 深空灰色 联通移动4...",
        "spec": [{
          "goods_price": 2799.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_491561631027151.jpg"
        }]
      }, {
        "goods_name": "APPLE IPHONE X(A1903) 64G 深空灰色 联通移动4...",
        "spec": [{
          "goods_price": 2799.00
        }],
        "image": [{
          "file_path": "http://img.wgmf.com/pro_1_541561631027154.jpg"
        }]
      }],
    scrollTop: 0,
  },

  onLoad: function() {
    var that = this;

    // 设置页面标题
    //App.setTitle();
    // 设置navbar标题、颜色
    //App.setNavigationBar();
    // 获取首页数据
    //this.getIndexData();
    that.setData({
      // lunboData: data.lunboData,
      // customerbar: data.customerbar
    })
  },

  /**
   * 获取首页数据
   */
  getIndexData: function() {
    let _this = this;
    // App._get('index/page', {}, function (result) {
    //   _this.setData(result.data);
    // });

    __this.setData(result.data);
  },

  /**
   * 计算图片高度
   */
  imagesHeight: function(e) {
    let imgId = e.target.dataset.id,
      itemKey = e.target.dataset.itemKey,
      ratio = e.detail.width / e.detail.height, // 宽高比
      viewHeight = 750 / ratio, // 计算的高度值
      imgHeights = this.data.imgHeights;

    // 把每一张图片的对应的高度记录到数组里
    if (typeof imgHeights[itemKey] === 'undefined') {
      imgHeights[itemKey] = {};
    }
    imgHeights[itemKey][imgId] = viewHeight;

    // 第一种方式
    let imgCurrent = this.data.imgCurrent;
    if (typeof imgCurrent[itemKey] === 'undefined') {
      imgCurrent[itemKey] = Object.keys(this.data.items[itemKey].data)[0];
    }
    this.setData({
      imgHeights,
      imgCurrent
    });
  },

  bindChange: function(e) {
    let itemKey = e.target.dataset.itemKey,
      imgCurrent = this.data.imgCurrent;
    // imgCurrent[itemKey] = e.detail.current;
    imgCurrent[itemKey] = e.detail.currentItemId;
    this.setData({
      imgCurrent
    });
  },

  goTop: function(t) {
    this.setData({
      scrollTop: 0
    });
  },

  scroll: function(t) {
    this.setData({
      indexSearch: t.detail.scrollTop
    }), t.detail.scrollTop > 300 ? this.setData({
      floorstatus: !0
    }) : this.setData({
      floorstatus: !1
    });
  },

  onShareAppMessage: function() {
    return {
      title: "首页",
      desc: "",
      path: "/pages/index/index"
    };
  }
});